package com.canoe.common;

import org.apache.commons.lang3.StringUtils;

/**
 * 一级指令枚举
 *
 * @author: btm
 * @time: 21:40 2020/9/21
 **/
public enum FirstLevelOrder {

    /**
     * text文件操作
     */
    TEXT("text"),

    /**
     * 命令模版，使用确定好的模版命令，合并上变动命令内容，共同执行命令
     */
    TEMPLATE("template")
    ;

    private String orderName;

    FirstLevelOrder(String orderName) {
        this.orderName = orderName;
    }

    public String getOrderName() {
        return orderName;
    }

    /**
     * 通过命令的名字，找到对应的命令
     * @param orderName 一级指令名称
     * @return FirstLevelOrder
     */
    public static FirstLevelOrder findByOrderName(String orderName) {
        if (StringUtils.isNotBlank(orderName)) {
            for (FirstLevelOrder firstLevelOrder : FirstLevelOrder.values()) {
                if (orderName.equals(firstLevelOrder.getOrderName())) {
                    return firstLevelOrder;
                }
            }
        }
        throw new CanoeException("unsupported first level order: " + orderName);
    }
}
